/**
 * @description
 * 当前版本号为 versionManager.version
 * 版本号的增改策略如下：
 * 每次调用对应函数方法时，对应版本号 +1, 下级版本号清零
 * @example
 * versionManager.version = V0.11.12;
 * versionManager.patch() // version => V0.11.13
 * versionManager.minor() // version => V0.12.0
 * versionManager.major() // version => V1.0.0
 * versionManager.rollback() // 回退到上一次的版本号 v0.12.0
 */

const versionManager = {
  versionOld: ["V0.11.12"],
  version: "V0.11.12",
  patch() {
    var arr = this.version.split(".");
    arr[2] = parseInt(arr[2]) + 1;

    var obj = arr.join(".");
    this.version = obj;

    console.log(this.versionOld);

    this.versionOld.push(this.version);
  },
  minor() {
    var arr = this.version.split(".");
    arr[2] = 0;

    arr[1] = parseInt(arr[1]) + 1;
    obj = arr.join(".");
    this.version = obj;
    this.versionOld.push(this.version);
  },
  major() {
    var arr = this.version.split(".");
    arr[2] = 0;
    arr[1] = 0;
    var reg = new RegExp(/\d+/g);

    arr[0] = parseInt(arr[0].match(reg)[0]) + 1;
    arr[0] = "v" + arr[0];

    obj = arr.join(".");

    this.version = obj;

    this.versionOld.push(this.version);
    // console.log(this.versionOld);
    
    

  },
  rollback() {
    if (this.versionOld) {
      this.versionOld.pop();
      this.version = this.versionOld[this.versionOld.length-1];
    }
  },
};

versionManager.major();
console.log(versionManager.version);
versionManager.rollback();
console.log(versionManager.version);




console.log('-------------------------------------------------------------');
/**
 * @description
 * 当前版本号为 versionManager.version
 * 版本号的增改策略如下：
 * 每次调用对应函数方法时，对应版本号 +1, 下级版本号清零
 * @example
 * versionManager.version = V0.11.12;
 * versionManager.patch() // version => V0.11.13
 * versionManager.minor() // version => V0.12.0
 * versionManager.major() // version => V1.0.0
 * versionManager.rollback() // 回退到上一次的版本号 v0.12.0
 */

export const versionManager = {
    versionOld: ["V0.11.12"],
    version: "V0.11.12",
    patch() {
      var arr = this.version.split(".");
      arr[2] = parseInt(arr[2]) + 1;
  
      var obj = arr.join(".");
      this.version = obj;
  
      console.log(this.versionOld);
  
      this.versionOld.push(this.version);
    },
    minor() {
      var arr = this.version.split(".");
      arr[2] = 0;
  
      arr[1] = parseInt(arr[1]) + 1;
      obj = arr.join(".");
      this.version = obj;
      this.versionOld.push(this.version);
    },
    major() {
      var arr = this.version.split(".");
      arr[2] = 0;
      arr[1] = 0;
      var reg = new RegExp(/\d+/g);
  
      arr[0] = parseInt(arr[0].match(reg)[0]) + 1;
      arr[0] = "v" + arr[0];
  
      obj = arr.join(".");
  
      this.version = obj;
  
      this.versionOld.push(this.version);
      // console.log(this.versionOld);
      
      
  
    },
    rollback() {
      if (this.versionOld) {
        this.versionOld.pop();
        this.version = this.versionOld[this.versionOld.length-1];
      }
    },
  };
  